
import { Obj, Reg, Comb, Obuf, Ibuf, M9k, Mout, Mul, } from './defs';

export const pre_proc = (data: Buffer, assign: { [key: string]: string }, objs: Obj[]) => {
  var s = data.toString();
  var ss = s.split("\r\n");
  var obj: Obj | null = null;
  var appendText: string | null = null;
  ss.forEach((line) => {
    line = line.trim();
    if (line.startsWith("assign")) {
      line = line.substring(7, line.length - 1);
      var kv = line.split(" = ");
      var k = kv[0].trim();
      var v = kv[1].trim();
      assign[k] = v;
      return;
    }

    if (line.startsWith("// Location:")) {
      obj = { lines: [], type: "", name: "" };
    }
    if (obj) {
      if (appendText) {
        appendText = appendText + line;
        if (line.indexOf(")") < 0) {
        } else {
          obj.lines.push(appendText);
          appendText = null;
        }
      } else {
        if (line.startsWith(".") && line.indexOf(")") < 0) {
          appendText = line;
        } else {
          obj.lines.push(line);
        }
      }
    }
    if (line == "// synopsys translate_on") {
      if (obj) {
        objs.push(obj);
      }
      obj = null;
    }
  });

};